﻿<?php
require_once('konfiguration.html');
$files=array("english_french"=>"French-english.txt",
"english_portuguese"=>"Portuguese-english.txt",
"english_spanish"=>"Spanish-english.txt",
"english_italian"=>"Italian-english.txt");
//$files=array("english_spanish"=>"Spanish-english.txt");
//$files=array("english_italian"=>"Italian-english.txt");
foreach ($files as $key=> $value)
{
   $lines=file($value);
   print "$key";
   foreach($lines as $line)
   { 
      preg_match_all('/^([\w]*)[\s]+(.*?)\[(.*?)\]/',$line,$matches,PREG_PATTERN_ORDER);
      if (!$matches[3])  preg_match_all('/^([\w]*)[\s]+(.*)/',$line,$matches,PREG_PATTERN_ORDER);
	  //[\w, áéíóúàèìòù\/]
      $word=$matches[1][0];
      $translations=explode(',',$matches[2][0] );
	  print_r( $matches);
	  print_r($translations);
	  print $translations[0].'<br>';
      $word_class=$matches[3][0];
      //print_r ($matches);
      foreach ($translations as $translation) 
      { if ($translation[-1]=='/') $translation= substr  (  $translation  ,  0  ,-1 );
      mysql_query("INSERT INTO alltranslations2 (language_combo, word, translation, `word class`) VALUES ('$key','$word','$translation','$word_class')");
       
       }	
	$index+=1;
	  set_time_limit(10);
   
   }

}
/*$line= "aardvark	oricterope, porco-da-terra[Noun]";
preg_match_all('/^([\w]*)[\s]+([\w-, ]*)\[(.*?)\]/',$line,$matches,PREG_PATTERN_ORDER);
$word=$matches[1];
$translations=explode($matches[2], ',');
$word_class=$matches[3];
print_r ($matches);
*/
//,?(.*?)? \[(.*?)\]+/

?>